import type { RespBusData } from "@/api/common/type"
import type { ProductCate, Attr } from "./type"
import request from "@/utils/request";

enum API {
    GET_CATEGORY_1 = '/product/product_category/getCategory1',
    GET_CATEGORY_2 = '/product/product_category/getCategory2',
    GET_CATEGORY_3 = '/product/product_category/getCategory3',
    GET_ATTR_LIST = 'product/product_attribute/list',
    SAVEATTR_URL = '/product/product_attribute/saveAttrInfo',
    EXIST_URL = '/product/product_attribute/exist',
    DELATTR_URL = '/product/product_attribute/delete/'
}

// 请求一级分类列表
export const reqCategory1List = () => request.get<any, RespBusData<Array<ProductCate>>>(API.GET_CATEGORY_1)
// 请求二级分类列表
export const reqCategory2List = (category1Id: number|string) => request.get<any, RespBusData<ProductCate[]>>(API.GET_CATEGORY_2 + `/${category1Id}`)
// 请求三级分类列表
export const reqCategory3List = (category2Id: number|string) => request.get<any, RespBusData<ProductCate[]>>(API.GET_CATEGORY_3 + `/${category2Id}`)
// 请求属性列表
export const reqAttrList = (category3Id: number|string) => request.get<any, RespBusData<Attr[]>>(API.GET_ATTR_LIST, { params: { categoryId: category3Id} }  )
// 添加属性与属性值
export const reqSaveAttr = (data: Attr) => request.post<any, RespBusData<any>>(API.SAVEATTR_URL, data)
// 校验属性是否存在
export const reqAttrExist = (data: Attr) => request.post<any, RespBusData<any>>(API.EXIST_URL, data )
// 删除属性
export const reqDeleteAttr = (id: number|string) => request.post<any, RespBusData<any>>(API.DELATTR_URL + id)